﻿using Bll;
using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Myproject.BSM.Ashx.PcChannel
{
    /// <summary>
    /// NewsEdit 的摘要说明
    /// </summary>
    public class NewsEdit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Form["pc_Channel_NewsEdit_ID"];
            string title = context.Request.Form["pc_Channel_NewsEdit_title"];
            string etitle = context.Request.Form["pc_Channel_NewsEdit_etitle"];
            string subtitle = context.Request.Form["pc_Channel_NewsEdit_subtitle"];
            string esubtitle = context.Request.Form["pc_Channel_NewsEdit_esubtitle"];
            //string read = context.Request.Form["pc_Channel_NewsEdit_read"];
            //string eread = context.Request.Form["pc_Channel_NewsEdit_eread"];
            //string pic = context.Request.Form["doc_pic"];
            string channelID = context.Request.Form["pc_Channel_NewsEdit_channelID"];
            string show = context.Request.Form["pc_Channel_NewsEdit_show"];
            string showtime = context.Request.Form["pc_Channel_NewsEdit_showtime"];
            string url = context.Request.Form["pc_Channel_NewsEdit_url"];
            string text = context.Request.Form["txtArticleContent"];
            string etext = context.Request.Form["txtArticleContent2"];
            string Source = context.Request.Form["pc_Channel_NewsEdit_Source"];
            string Editor = context.Request.Form["pc_Channel_NewsEdit_Editor"];
            string ReadTmes = context.Request.Form["pc_Channel_NewsEdit_ReadTmes"];

            if (id == "0")
            {
                NewsModel model = new NewsModel();
                model.Title = title;
                model.ETitle = etitle;
                model.SubTitle = subtitle;
                model.ESubTitle = esubtitle;
                model.WebChannelId = int.Parse(channelID);
                if (string.IsNullOrEmpty(show))
                { model.show = false; }
                else
                {
                    model.show = bool.Parse(show);
                }
                model.ShowTime = DateTime.Parse(showtime);
                model.WebContent = text;
                model.EWebContent = etext;
                model.Editor = Editor;
                model.ReadTmes = int.Parse(ReadTmes);
                model.Source = Source;
                model.AdminId = int.Parse(cookieHelp.AdminId);
                if (new NewsBLL().Add(model) > 0)
                {

                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "添加图文成功！", "pc_channel_newslist", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "添加图文失败！", "pc_channel_newslist", "", "", true, "", ""));
                }
            }
            else {

                NewsModel model = new NewsBLL().GetModel(int.Parse(id));
                model.Title = title;
                model.ETitle = etitle;
                model.SubTitle = subtitle;
                model.ESubTitle = esubtitle;
                model.WebChannelId = int.Parse(channelID);
                if (string.IsNullOrEmpty(show))
                { model.show = false; }
                else
                {
                    model.show = bool.Parse(show);
                }
                model.ShowTime = DateTime.Parse(showtime);
                model.WebContent = text;
                model.EWebContent = etext;
                model.Editor = Editor;
                model.ReadTmes = int.Parse(ReadTmes);
                model.Source = Source;
                model.AdminId = int.Parse(cookieHelp.AdminId);

                if (new NewsBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改图文成功！", "pc_channel_newslist", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改图文失败！", "pc_channel_newslist", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}